import codecs
#对数据进行处理
# wordIn = "user_tag_query.10W.TRAIN"
# wordOut = "output.txt"
#
# with codecs.open(wordIn, "r", encoding="GBK", errors="ignore") as inStream, codecs.open(wordOut, "w", encoding="UTF-8") as outStream:
#     for line in inStream:
#         c = list(line)
#         for i in range(39, len(line)):
#             outStream.write(c[i])
#             if c[i] == '\t':
#                 outStream.write('\n')
########################################################################
#统计次数
# 打开文件并读取内容
# file_path = "output.txt"
#
# with open(file_path, "r", encoding="UTF-8") as file:
#     text = file.read()
#
# # 要搜索的关键词
# keywords = ["中秋节", "教师节", "美食"]
#
# # 初始化关键词计数字典
# keyword_counts = {keyword: 0 for keyword in keywords}
#
# # 搜索并统计关键词
# for keyword in keywords:
#     keyword_counts[keyword] = text.count(keyword)
#
# # 输出关键词统计结果
# for keyword, count in keyword_counts.items():
#     print(f"{keyword}: {count} 次出现")

################################################################
#统计关键词的出现的词组并且写入文件
# 打开输入文件和输出文件
# input_file_path = "output.txt"
# output_file_path = "output_with_keywords.txt"
#
# with open(input_file_path, "r", encoding="UTF-8") as input_file, open(output_file_path, "w",
#                                                                       encoding="UTF-8") as output_file:
#     # 要搜索的关键词
#     keywords = ["体验"]
#
#     # 遍历输入文件的每一行
#     for line in input_file:
#         # 检查每个关键词是否在当前行中出现
#         if any(keyword in line for keyword in keywords):
#             # 如果至少一个关键词出现在当前行，将该行写入输出文件
#
#             output_file.write(line)
